/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingServPoolManageInfo: {
                housekeepingServPools: [],
                total: 0,
                records: 1,
                moreCondition: false,
                states: [],
                conditions: {
                    servName: '',
                    state: '',
                    applyName: '',
                    applyTel: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listHousekeepingServPools(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('housekeeping_serv_pool', "state", function (_data) {
                $that.housekeepingServPoolManageInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('housekeepingServPoolManage', 'listHousekeepingServPool', function (_param) {
                $that._listHousekeepingServPools(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingServPools(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingServPools: function (_page, _rows) {
                $that.housekeepingServPoolManageInfo.conditions.page = _page;
                $that.housekeepingServPoolManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.housekeepingServPoolManageInfo.conditions
                };
                param.params.applyName = param.params.applyName.trim();
                param.params.servName = param.params.servName.trim();
                param.params.applyTel = param.params.applyTel.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingServPool/queryHousekeepingServPool',
                    param,
                    function (json, res) {
                        var _housekeepingServPoolManageInfo = JSON.parse(json);
                        $that.housekeepingServPoolManageInfo.total = _housekeepingServPoolManageInfo.total;
                        $that.housekeepingServPoolManageInfo.records = _housekeepingServPoolManageInfo.records;
                        $that.housekeepingServPoolManageInfo.housekeepingServPools = _housekeepingServPoolManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingServPoolManageInfo.records,
                            dataCount: $that.housekeepingServPoolManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _queryHousekeepingServPoolMethod: function () {
                $that._listHousekeepingServPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingServPoolMethod: function () {
                $that.housekeepingServPoolManageInfo.conditions.servName = "";
                $that.housekeepingServPoolManageInfo.conditions.state = "";
                $that.housekeepingServPoolManageInfo.conditions.applyName = "";
                $that.housekeepingServPoolManageInfo.conditions.applyTel = "";
                $that._listHousekeepingServPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openAddTelSerModal: function () {
                vc.emit('addOwnerRepair', 'openAddOwnerRepairModal', $that.housekeepingServPoolManageInfo.conditions);
            },
            _openDispatchHousekeepingModel: function (_repair) {
                _repair.action = "DISPATCH";
                vc.emit('dispatchHousekeeping', 'openDispatchHousekeepingModal', _repair);
            },
            _moreCondition: function () {
                if ($that.housekeepingServPoolManageInfo.moreCondition) {
                    $that.housekeepingServPoolManageInfo.moreCondition = false;
                } else {
                    $that.housekeepingServPoolManageInfo.moreCondition = true;
                }
            },
            _openDetail: function (_pool) {
                vc.jumpToPage('/#/pages/housekeeping/housekeepingServDetail?poolId=' + _pool.poolId)
            },
            _openAddHousekeepingServPoolUserModal: function (_pool) {
                let _data = {
                    shopId: vc.getCurrentCommunity().shopId,
                    poolId: _pool.poolId
                };
                vc.http.apiPost(
                    '/housekeepingServPoolUser/poolGrabbing',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.emit('housekeepingServPoolManage', 'listHousekeepingServPool', {});
                            vc.toast("操作成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _openReleaseHousekeepingServPoolUserModal: function (_pool) {
                let _data = {
                    shopId: vc.getCurrentCommunity().shopId,
                    poolId: _pool.poolId
                };
                vc.http.apiPost(
                    '/housekeepingServPoolUser/releaseRepair',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.emit('housekeepingServPoolManage', 'listHousekeepingServPool', {});
                            vc.toast("操作成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            }
        }
    });
})(window.vc);
